//
//  ProgressView.swift
//  WBSwift
//
//  Created by maker on 2016/11/25.
//  Copyright © 2016年 maker. All rights reserved.
//

import UIKit

class ProgressView: UIView {
    
    var progress : CGFloat = 0.0{
        didSet{
            setNeedsDisplay()
        }
    }
    
    override func draw(_ rect: CGRect) {
        //1.父类重绘
        super.draw(rect)
        
        //2.创建圆路径
        let centerPoint = CGPoint(x: rect.size.width * 0.5,y: rect.size.width * 0.5)
        let radius = rect.size.width * 0.5 - 3
        let startAngle = CGFloat(-M_PI_2)
        let endAngle = CGFloat(2 * M_PI) * progress + CGFloat(startAngle)
        
        let path = UIBezierPath(arcCenter: centerPoint, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true)
    
        //3.添加到中心点的线
        path.addLine(to: centerPoint)
        path.close()
        
        //4.设置属性,并开始绘制
        UIColor(white: 1, alpha: 0.4).setFill()
      
        path.fill()
        
    }


}
